home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / plaf / basic / BasicInternalFrameTitlePane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  8.1 KB  |  250 lines

  1. package javax.swing.plaf.basic;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.LayoutManager;
  10. import java.awt.Toolkit;
  11. import java.beans.PropertyChangeListener;
  12. import javax.swing.AbstractButton;
  13. import javax.swing.Action;
  14. import javax.swing.Icon;
  15. import javax.swing.JButton;
  16. import javax.swing.JComponent;
  17. import javax.swing.JInternalFrame;
  18. import javax.swing.JMenu;
  19. import javax.swing.JMenuBar;
  20. import javax.swing.JMenuItem;
  21. import javax.swing.JSeparator;
  22. import javax.swing.UIManager;
  23. import javax.swing.event.InternalFrameEvent;
  24.  
  25. public class BasicInternalFrameTitlePane extends JComponent {
  26.    protected JMenuBar menuBar;
  27.    protected JButton iconButton;
  28.    protected JButton maxButton;
  29.    protected JButton closeButton;
  30.    protected JMenu windowMenu;
  31.    protected JInternalFrame frame;
  32.    protected Color selectedTitleColor;
  33.    protected Color selectedTextColor;
  34.    protected Color notSelectedTitleColor;
  35.    protected Color notSelectedTextColor;
  36.    protected Icon maxIcon;
  37.    protected Icon minIcon;
  38.    protected Icon iconIcon;
  39.    protected Icon closeIcon;
  40.    protected PropertyChangeListener propertyChangeListener;
  41.    protected Action closeAction;
  42.    protected Action maximizeAction;
  43.    protected Action iconifyAction;
  44.    protected Action restoreAction;
  45.    protected Action moveAction;
  46.    protected Action sizeAction;
  47.    protected static final String CLOSE_CMD = "Close";
  48.    protected static final String ICONIFY_CMD = "Minimize";
  49.    protected static final String RESTORE_CMD = "Restore";
  50.    protected static final String MAXIMIZE_CMD = "Maximize";
  51.    protected static final String MOVE_CMD = "Move";
  52.    protected static final String SIZE_CMD = "Size";
  53.    // $FF: synthetic field
  54.    static Class class$javax$swing$JInternalFrame;
  55.  
  56.    public BasicInternalFrameTitlePane(JInternalFrame var1) {
  57.       this.frame = var1;
  58.       this.installTitlePane();
  59.    }
  60.  
  61.    public void addNotify() {
  62.       super.addNotify();
  63.       this.addSystemMenuItems(this.windowMenu);
  64.       this.enableActions();
  65.    }
  66.  
  67.    protected void addSubComponents() {
  68.       ((Container)this).add(this.menuBar);
  69.       ((Container)this).add(this.iconButton);
  70.       ((Container)this).add(this.maxButton);
  71.       ((Container)this).add(this.closeButton);
  72.    }
  73.  
  74.    protected void addSystemMenuItems(JMenu var1) {
  75.       JMenuItem var2 = var1.add(this.restoreAction);
  76.       ((AbstractButton)var2).setMnemonic('R');
  77.       var2 = var1.add(this.moveAction);
  78.       ((AbstractButton)var2).setMnemonic('M');
  79.       var2 = var1.add(this.sizeAction);
  80.       ((AbstractButton)var2).setMnemonic('S');
  81.       var2 = var1.add(this.iconifyAction);
  82.       ((AbstractButton)var2).setMnemonic('n');
  83.       var2 = var1.add(this.maximizeAction);
  84.       ((AbstractButton)var2).setMnemonic('x');
  85.       var1.add(new JSeparator());
  86.       var2 = var1.add(this.closeAction);
  87.       ((AbstractButton)var2).setMnemonic('C');
  88.    }
  89.  
  90.    protected void assembleSystemMenu() {
  91.       this.menuBar = this.createSystemMenuBar();
  92.       this.windowMenu = this.createSystemMenu();
  93.       this.menuBar.add(this.windowMenu);
  94.       this.enableActions();
  95.    }
  96.  
  97.    // $FF: synthetic method
  98.    static Class class$(String var0) {
  99.       try {
  100.          return Class.forName(var0);
  101.       } catch (ClassNotFoundException var2) {
  102.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  103.       }
  104.    }
  105.  
  106.    protected void createActions() {
  107.       this.maximizeAction = new MaximizeAction(this);
  108.       this.iconifyAction = new IconifyAction(this);
  109.       this.closeAction = new CloseAction(this);
  110.       this.restoreAction = new RestoreAction(this);
  111.       this.moveAction = new MoveAction(this);
  112.       this.sizeAction = new SizeAction(this);
  113.    }
  114.  
  115.    protected void createButtons() {
  116.       this.iconButton = new NoFocusButton(this);
  117.       this.iconButton.addActionListener(this.iconifyAction);
  118.       this.maxButton = new NoFocusButton(this);
  119.       this.maxButton.addActionListener(this.maximizeAction);
  120.       this.closeButton = new NoFocusButton(this);
  121.       this.closeButton.addActionListener(this.closeAction);
  122.       this.setButtonIcons();
  123.    }
  124.  
  125.    protected LayoutManager createLayout() {
  126.       return new TitlePaneLayout(this);
  127.    }
  128.  
  129.    protected PropertyChangeListener createPropertyChangeListener() {
  130.       return new PropertyChangeHandler(this);
  131.    }
  132.  
  133.    protected JMenu createSystemMenu() {
  134.       return new JMenu("    ");
  135.    }
  136.  
  137.    protected JMenuBar createSystemMenuBar() {
  138.       this.menuBar = new SystemMenuBar(this);
  139.       this.menuBar.setBorderPainted(false);
  140.       return this.menuBar;
  141.    }
  142.  
  143.    protected void enableActions() {
  144.       this.restoreAction.setEnabled(this.frame.isMaximum() || this.frame.isIcon());
  145.       this.maximizeAction.setEnabled(this.frame.isMaximizable() && !this.frame.isMaximum());
  146.       this.iconifyAction.setEnabled(this.frame.isIconifiable() && !this.frame.isIcon());
  147.       this.closeAction.setEnabled(this.frame.isClosable());
  148.       this.sizeAction.setEnabled(false);
  149.       this.moveAction.setEnabled(false);
  150.    }
  151.  
  152.    protected void installDefaults() {
  153.       this.maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon");
  154.       this.minIcon = UIManager.getIcon("InternalFrame.minimizeIcon");
  155.       this.iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
  156.       this.closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
  157.       this.selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
  158.       this.selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
  159.       this.notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
  160.       this.notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
  161.    }
  162.  
  163.    protected void installListeners() {
  164.       this.propertyChangeListener = this.createPropertyChangeListener();
  165.       this.frame.addPropertyChangeListener(this.propertyChangeListener);
  166.    }
  167.  
  168.    protected void installTitlePane() {
  169.       this.installDefaults();
  170.       this.installListeners();
  171.       this.createActions();
  172.       this.enableActions();
  173.       ((Container)this).setLayout(this.createLayout());
  174.       this.assembleSystemMenu();
  175.       this.createButtons();
  176.       this.addSubComponents();
  177.    }
  178.  
  179.    public void paintComponent(Graphics var1) {
  180.       boolean var2 = this.frame.isSelected();
  181.       if (var2) {
  182.          var1.setColor(this.selectedTitleColor);
  183.       } else {
  184.          var1.setColor(this.notSelectedTitleColor);
  185.       }
  186.  
  187.       var1.fillRect(0, 0, ((JComponent)this).getWidth(), ((JComponent)this).getHeight());
  188.       if (this.frame.getTitle() != null) {
  189.          Font var3 = var1.getFont();
  190.          var1.setFont(UIManager.getFont("InternalFrame.titleFont"));
  191.          if (var2) {
  192.             var1.setColor(this.selectedTextColor);
  193.          } else {
  194.             var1.setColor(this.notSelectedTextColor);
  195.          }
  196.  
  197.          FontMetrics var4 = var1.getFontMetrics();
  198.          int var5 = var4.getHeight() - var4.getLeading();
  199.          int var6 = (18 - var5) / 2 + var4.getAscent() + var4.getLeading();
  200.          var1.drawString(this.frame.getTitle(), this.menuBar.getX() + this.menuBar.getWidth() + 2, var6);
  201.          var1.setFont(var3);
  202.       }
  203.  
  204.    }
  205.  
  206.    protected void postClosingEvent(JInternalFrame var1) {
  207.       InternalFrameEvent var2 = new InternalFrameEvent(var1, 25550);
  208.       if ((class$javax$swing$JInternalFrame != null ? class$javax$swing$JInternalFrame : (class$javax$swing$JInternalFrame = class$("javax.swing.JInternalFrame"))).getClassLoader() == null) {
  209.          try {
  210.             Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(var2);
  211.             return;
  212.          } catch (SecurityException var3) {
  213.          }
  214.       }
  215.  
  216.       ((Component)var1).dispatchEvent(var2);
  217.    }
  218.  
  219.    public void removeNotify() {
  220.       super.removeNotify();
  221.       if (this.windowMenu != null) {
  222.          this.windowMenu.removeAll();
  223.       }
  224.  
  225.       this.uninstallDefaults();
  226.    }
  227.  
  228.    protected void setButtonIcons() {
  229.       if (this.frame.isIcon()) {
  230.          this.iconButton.setIcon(this.minIcon);
  231.          this.maxButton.setIcon(this.maxIcon);
  232.       } else if (this.frame.isMaximum()) {
  233.          this.iconButton.setIcon(this.iconIcon);
  234.          this.maxButton.setIcon(this.minIcon);
  235.       } else {
  236.          this.iconButton.setIcon(this.iconIcon);
  237.          this.maxButton.setIcon(this.maxIcon);
  238.       }
  239.  
  240.       this.closeButton.setIcon(this.closeIcon);
  241.    }
  242.  
  243.    protected void showSystemMenu() {
  244.       this.windowMenu.doClick();
  245.    }
  246.  
  247.    protected void uninstallDefaults() {
  248.    }
  249. }
  250.